﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Klinkby.Scheduler
{
    /// <summary>
    /// Specifies a time of day for a daily basis for <see cref="Scheduler"/>.
    /// </summary>
    [Serializable]
    public class DailyInterval : MarshalByRefObject, IInterval
    {
        readonly TimeSpan _timeOfDay;

        public DailyInterval(TimeSpan timeOfDay)
        {
            if (timeOfDay.TotalHours >= 24)
                throw new ArgumentException("Must be less than 24 hours", "timeOfDay");
            _timeOfDay = timeOfDay;
        }

        #region IInterval Members

        public DateTime Next
        {
            get
            {
                return (_timeOfDay > DateTime.Now.TimeOfDay)
                    ? DateTime.Today + _timeOfDay
                    : (DateTime.Today + _timeOfDay).AddDays(1);
            }
        }

        #endregion
    }

}
